#include "client.h"
#include "file.h"
#include "ui_file.h"

#include <QInputDialog>
#include <QMessageBox>



File::File(QWidget *parent) : QWidget(parent), ui(new Ui::File)
{
    ui->setupUi(this);
    m_strUserPath = QString("%1/%2").arg(Client::getInstance().getRootPath()).arg(Client::getInstance().m_strLoginName);
    m_strCurPath = m_strUserPath;
}

File::~File()
{
    delete ui;
}

void File::on_mkdir_PB_clicked()
{
    QString strNewDir = QInputDialog::getText(this, "新建文件夹", "新建文件夹名");
    if(strNewDir.isEmpty() || strNewDir.toStdString().size() > 32){
        QMessageBox::information(this, "新建文件夹", "文件夹名长度非法");
        return;
    }
    PDU* pdu = mkPDU(ENUM_MSG_TYPE_MKDIR_REQUEST, m_strCurPath.toStdString().size() + 1);
    memcpy(pdu->caData, strNewDir.toStdString().c_str(), 32);
    memcpy(pdu->caMsg, m_strCurPath.toStdString().c_str(), m_strCurPath.toStdString().size());
    Client::getInstance().sendMsg(pdu);

}
